themingengine: Do pattern merging smarter
authorBenjamin Otte <otte@redhat.com>
Sat, 11 Jun 2011 02:06:22 +0000 (04:06 +0200)
committerBenjamin Otte <otte@redhat.com>
Sat, 11 Jun 2011 07:29:42 +0000 (09:29 +0200)
Create an intermdiate surface and fill() with it later. Instead of doing
clip + paint twice.

gtk/gtkthemingengine.c

index 51c80b431e9153efbd0aae3a74bda23a0364f9ca..863ea8c0505cde85221bf8f66da8fb29df733313 100644 (file)
@@ -1510,7 +1510,7 @@ render_background_internal (GtkThemingEngine *engine,
   cairo_pattern_t *pattern;
   GtkStateFlags flags;
   gboolean running;
-  gdouble progress, alpha = 1;
+  gdouble progress;
   GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
   GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
   GtkCssBorderRadius border_radius = { { 0, },  };
@@ -1641,22 +1641,22 @@ render_background_internal (GtkThemingEngine *engine,
             }
           else
             {
-              /* Different pattern types, or different color
-               * stop counts, alpha blend both patterns.
-               */
-              _cairo_round_rectangle_sides (cr, &border_radius,
-                                            0, 0, width, height,
-                                            SIDE_ALL);
+              cairo_save (cr);
+
+              cairo_rectangle (cr, 0, 0, width, height);
+              cairo_clip (cr);
+
+              cairo_push_group (cr);
 
               cairo_scale (cr, width, height);
               cairo_set_source (cr, other_pattern);
-              cairo_scale (cr, 1.0 / width, 1.0 / height);
-              cairo_fill_preserve (cr);
+              cairo_paint_with_alpha (cr, progress);
+              cairo_set_source (cr, pattern);
+              cairo_paint_with_alpha (cr, 1.0 - progress);
+
+              new_pattern = cairo_pop_group (cr);
 
-              /* Set alpha for posterior drawing
-               * of the target pattern
-               */
-              alpha = 1 - progress;
+              cairo_restore (cr);
             }
         }
       else if (pattern || other_pattern)
@@ -1740,17 +1740,7 @@ render_background_internal (GtkThemingEngine *engine,
   else
     gdk_cairo_set_source_rgba (cr, &bg_color);
 
-  if (alpha == 1)
-    {
-      cairo_fill (cr);
-    }
-  else
-    {
-      cairo_save (cr);
-      cairo_clip (cr);
-      cairo_paint_with_alpha (cr, alpha);
-      cairo_restore (cr);
-    }
+  cairo_fill (cr);
 
   if (pattern)
     cairo_pattern_destroy (pattern);